Use Windows.pkg
Use DFClient.pkg
Use cPatientDataDictionary.dd
Use cDoctorDataDictionary.dd
Use cApptDataDictionary.dd
Use cApptdetlDataDictionary.dd
Use cPaymentsDataDictionary.dd
Use DFEntry.pkg
Use DATES.MOD
Use time_functions.pkg
Use common_domain_logic.pkg
Use common.pkg
Use DoctorAvailabilitySL.dg
Use dfallent.pkg
Use OfficeTimesSL.dg
Use dfLine.pkg

Deferred_View Activate_oAppointmentSetup for ;
Object oAppointmentSetup is a dbView
    Property Boolean pbApptSaveSuccess
    Property String psMboxCaption "Appointment Setup"
    Set Border_Style to Border_ClientEdge
    Set Size to 274 341
    Set Location to 4 4
    Set Label to "Appointment Setup"
    Set Icon to "doctor_plus.ico"
    
    Object oDOCTOR_DD is a cDoctorDataDictionary
        Set Field_Option Field DOCTOR.FIRST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field DOCTOR.LAST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field DOCTOR.START_TIME DD_DISPLAYONLY to True
        Set Field_Option Field DOCTOR.LUNCH_HOUR DD_DISPLAYONLY to True
        Set Field_Option Field DOCTOR.END_TIME DD_DISPLAYONLY to True
        Set Read_Only_State to True
        
        Procedure Set Field_Current_Value Integer iField String sVal
            Integer iDoctorFld
            
            Get_FieldNumber Doctor.Doctor# to iDoctorFld
            If (iField eq iDoctorFld) Begin
                Clear Doctor
                Move sVal to Doctor.Doctor#
                Find eq Doctor by Index.1
                If (Found) Begin
                    Send Request_Assign Doctor.File_Number
                End
                 Else Begin
                    Send Clear
                    Forward Set Field_Current_Value item iField to sVal
                    Set Field_Changed_State item iField to True
                 End
            End
             Else Forward Set Field_Current_Value item iField to sVal
        End_Procedure //Set Field_Current_Value
        
        Procedure Request_Save
            Boolean bPrevDisableUpdateFocusField
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Request_Save
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Request_Save
        
        Procedure Request_Assign Integer iPassedFile
            Integer iFile
            Boolean bPrevDisableUpdateFocusField
            If (Num_Arguments = 0) Get Main_File to iFile
                Else If (iPassedFile = 0) Get Main_file to iFile
                Else Move iPassedFile to iFile
            Move iFile to Filenumber
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Request_Assign iFile
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Request_Assign
        
        Procedure Clear
            Boolean bPrevDisableUpdateFocusField
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Clear
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Clear
        
        Procedure Clear_All
            Boolean bPrevDisableUpdateFocusField
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Clear_All
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Clear_All
        
        Procedure Update_Focus_Field
            If (not(pbDisableUpdateFocusField(Self))) Forward Send Update_Focus_Field
        End_Procedure // Update_Focus_Field
    End_Object

    Object oPATIENT_DD is a cPatientDataDictionary
        Set Field_Option Field PATIENT.FIRST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field PATIENT.LAST_NAME DD_DISPLAYONLY to True
        Set Field_Option Field PATIENT.BALANCE_DUE DD_DISPLAYONLY to True
        Set Field_Option Field PATIENT.MIDDLE_INIT DD_DISPLAYONLY to True
        Set Read_Only_State to True
        
        Procedure Set Field_Current_Value Integer iField String sVal
            Integer iPatientFld
            Get_FieldNumber Patient.PATIENT# to iPatientFld
            If (iField eq iPatientFld) Begin
                Clear PATIENT
                Move sVal to PATIENT.PATIENT#
                Find eq PATIENT by Index.1
                If (Found) Begin
                    Send Request_Assign PATIENT.File_Number
                End
                 Else Begin
                    Send Clear
                    Forward Set Field_Current_Value item iField to sVal
                    Set Field_Changed_State item iField to True
                 End
            End
             Else Forward Set Field_Current_Value item iField to sVal
        End_Procedure //Set Field_Current_Value
        
        Procedure Request_Save
            Boolean bPrevDisableUpdateFocusField
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Request_Save
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Request_Save
        
        Procedure Request_Assign Integer iPassedFile
            Integer iFile
            Boolean bPrevDisableUpdateFocusField
            If (Num_Arguments = 0) Get Main_File to iFile
                Else If (iPassedFile = 0) Get Main_file to iFile
                Else Move iPassedFile to iFile
            Move iFile to Filenumber
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Request_Assign iFile
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Request_Assign
        
        Procedure Clear
            Boolean bPrevDisableUpdateFocusField
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Clear
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Clear
        
        Procedure Clear_All
            Boolean bPrevDisableUpdateFocusField
            Get pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
            Set pbDisableUpdateFocusField to True
            Forward Send Clear_All
            Set pbDisableUpdateFocusField to bPrevDisableUpdateFocusField
        End_Procedure // Clear_All
        
        Procedure Update_Focus_Field
            If (not(pbDisableUpdateFocusField(Self))) Forward Send Update_Focus_Field
        End_Procedure // Update_Focus_Field
    End_Object

    Object oAPPT_DD is a cApptDataDictionary
        Set DDO_Server to oDOCTOR_DD
        Set DDO_Server to oPATIENT_DD
        
        Function Request_validate Returns Integer
            Boolean bFail bHasRecord
            
            Get HasRecord to bHasRecord
            Forward Get Request_Validate to bFail
            If (not(bfail)) Get CheckChangedPatient to bFail
            If (not(bFail)) Get CheckPatientExists to bFail
            If (not(bFail)) Get CheckDoctorExists to bFail
            If (not(bFail)) Get CheckIsApptTimeBeforeNow to bFail
            If (not(bFail)) Get CheckIsPatientDoubleBooked to bFail
            Function_Return bFail
        End_Function
        
        Function Validate_Save Returns Integer
            Integer iFail iMaxAllowedBalance
            
            Move 750 to iMaxAllowedBalance
            Forward Get Validate_Save to iFail
            If (not(iFail)) Begin
                If (PATIENT.BALANCE_DUE > iMaxAllowedBalance) Begin
                    Move True to iFail
                    Error DFERR_OPERATOR ("Patient balance for" * patient.Last_Name * "," * patient.first_name * ":" * (String(PATIENT.BALANCE_DUE)) + "\n\nPatient exceeds the maximum allowed balance of 750. Unable to create appointment.")
                End
            End
            Function_Return iFail
        End_Function
        
        Function CheckChangedPatient Returns Boolean
            Integer iIsExisting iPatient#New iPatient#Old
            Boolean bFail
            
            Move False to bFail
            Move APPT.RECNUM to iIsExisting
            Move PATIENT.PATIENT# to iPatient#New
            Get Field_Current_Value Field APPT.PATIENT# to iPatient#Old
            If (iIsExisting) Begin
                If (iPatient#New <> iPatient#Old) Begin
                    Send Info_Box "Patients cannot be changed in existing appointments."
                    Move True to bFail
                End
            End
            Function_Return bFail
        End_Function
        
        Function CheckIsApptTimeBeforeNow Returns Boolean
            DateTime dtAppt dtCurrent
            Integer iTime iAppt# iRecnum
            Date dDate
            Boolean bFail bDateChanged bTimeChanged bHasRecord
    
            Move False to bFail
            Get Field_Current_Value Field APPT.APPT# to iAppt#
            Get Field_Current_Value Field APPT.Date to dDate
            Get Field_Current_Value Field APPT.Time to iTime
            Get HasRecord to bHasRecord
            
            If (bHasRecord) Begin
                Move APPT.RECNUM to iRecnum
                Clear APPT
                Move iAppt# to APPT.APPT#
                Find eq APPT by Index.1
                If (Found) Begin
                    Move (If(APPT.Date <> dDate, True, False)) to bDateChanged
                    Move (If(APPT.Time <> iTime, True, False)) to bTimeChanged
                End
            End
    
            If (not(bHasRecord) or (bHasRecord and (bTimeChanged or bDateChanged))) Begin
            Move (CurrentDateTime()) to dtCurrent
            Move (DateSetMilitaryTime(dtAppt, iTime)) to dtAppt
            Move (DateSetDate(dtAppt, dDate)) to dtAppt
                If ((dtAppt < dtCurrent)) Begin 
                    Move True to bFail
                    Send Info_Box "Cannot create a new appointment in the past, or modify an existing appointment to a date and time in the past." (psMboxCaption(Self))
                End
            End
            
            If (bHasRecord and (iRecnum and (APPT.RECNUM <> iRecnum))) Begin
                Clear APPT
                Move iRecnum to APPT.RECNUM
                Find eq APPT by Recnum
            End
            
            Function_Return bFail
        End_Function
        
        Function CheckIsPatientDoubleBooked Returns Boolean
            Boolean bFail
            Integer iPat# iTime iRecnum iAppt#
            Date dDate

            Move False to bFail
            Get Field_Current_Value of oPatient_DD Field patient.PATIENT# to iPat#
            Get Field_Current_Value of oAppt_DD Field APPT.Date to dDate
            Get Field_Current_Value of oAppt_DD Field APPT.Time to iTime
            Get Field_Current_Value of oAPPT_DD Field APPT.APPT# to iAppt#
            
            Move APPT.RECNUM to iRecnum
            Clear APPT
            Move iPat# to APPT.PATIENT#
            Move iTime to APPT.Time
            Move dDate to APPT.Date
            Find gt APPT by Index.3
            If (Found) Begin
                If (not(iAppt# = APPT.APPT#)) Begin //prevents validation from finding the validating record and failing
                    If ((APPT.PATIENT# = iPat#) and (APPT.Time = iTime) and (APPT.Date = dDate)) Begin
                        Move True to bFail
                        Send Info_Box ("Patients cannot be double booked. Patient #" + String(iPat#) + " already has an appointment scheduled on " ;
                            + String(dDate) + " at " + String(iTime) + ".") (psMboxCaption(Self))
                    End
                End
            End
            
            If (iRecnum and (iRecnum <> APPT.RECNUM)) Begin
                Clear APPT
                Move iRecnum to APPT.RECNUM
                Find eq APPT by recnum
            End
            Function_Return bFail
        End_Function
        
        Function CheckDoctorExists Returns Boolean
            Integer iDoc# 
            Boolean bFail bExists
            
            Move False to bFail
            Get Field_Current_Value of oDOCTOR_DD Field Doctor.doctor# to iDoc#
            Get DoctorExistsInDb iDoc# to bExists
            If (not(bExists)) Begin
                Move True to bFail
                Send Info_Box ("Doctor #" + (String(iDoc#)) + " doesn't exist. Please set up new doctors in the Doctor Setup view before proceeding.") (psMboxCaption(Self))
            End
            Function_Return bFail
        End_Function
        
        Function CheckPatientExists Returns Boolean
            Integer iPat#
            Boolean bFail bExists
            
            Move False to bFail
            Get Field_Current_Value of oPATIENT_DD Field PATIENT.PATIENT# to iPat#
            Get PatientExistsInDb iPat# to bExists
            If (not(bExists)) Begin
                Move True to bFail
                Send Info_Box ("Patient #" + (String(iPat#)) + " doesn't exist. Please set up new patients in the Patient Setup view before proceeding.") (psMboxCaption(Self))
            End
            Function_Return bFail
        End_Function
        
        Procedure Save_Main_File
            Forward Send Save_Main_File
            Set pbApptSaveSuccess to True //used to determine if save went through. if yes, then show msg box with appt information on confirm.
        End_Procedure
    End_Object

    Object oPAYMENTS_DD is a cPaymentsDataDictionary
        Set Constrain_file to APPT.File_number
        Set DDO_Server to oAPPT_DD
    End_Object

    Object oAPPTDETL_DD is a cApptdetlDataDictionary
        Set Constrain_file to APPT.File_number
        Set DDO_Server to oAPPT_DD
    End_Object

    Set Main_DD to oAPPT_DD
    Set Server to oAPPT_DD

    Object oPatientContainer is a dbGroup
        Set Size to 63 311
        Set Location to 3 15
        Set Server to oPATIENT_DD

        Object oAPPT_PATIENT_ is a dbForm
            Entry_Item PATIENT.PATIENT#
            Set Location to 16 6
            Set Size to 13 84
            Set Label to "Patient #"
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to JMode_Top
        End_Object

        Object oPATIENT_BALANCE_DUE is a dbForm
            Entry_Item PATIENT.BALANCE_DUE
            Set Location to 16 203
            Set Size to 13 78
            Set Label to "Balance Due"
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to JMode_Top
        End_Object

        Object oPATIENT_LAST_NAME is a dbForm
            Entry_Item PATIENT.LAST_NAME
            Set Location to 40 8
            Set Size to 13 120
            Set Label to "Last Name"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oPATIENT_MIDDLE_INIT is a dbForm
            Entry_Item PATIENT.MIDDLE_INIT
            Set Location to 40 135
            Set Size to 13 23
            Set Label to "Middle"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object
        Object oPATIENT_FIRST_NAME is a dbForm
            Entry_Item PATIENT.FIRST_NAME
            Set Location to 40 162
            Set Size to 13 119
            Set Label to "First Name"
            Set Label_Col_Offset to 0
            Set Label_Justification_Mode to JMode_Top
        End_Object
    End_Object

    Object oDoctorContainer is a dbGroup
        Set Size to 81 311
        Set Location to 76 15
        Set Server to oDOCTOR_DD

        Object oAPPT_DOCTOR_ is a dbForm
            Entry_Item DOCTOR.DOCTOR#
            Set Location to 15 11
            Set Size to 13 84
            Set Label to "Doctor #"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oDOCTOR_START_TIME is a dbForm
            Entry_Item DOCTOR.START_TIME
            Set Location to 15 171
            Set Size to 13 30
            Set Label to "Start"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oDOCTOR_LUNCH_HOUR is a dbForm
            Entry_Item DOCTOR.LUNCH_HOUR
            Set Location to 15 211
            Set Size to 13 30
            Set Label to "Lunch"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oDOCTOR_END_TIME is a dbForm
            Entry_Item DOCTOR.END_TIME
            Set Location to 15 251
            Set Size to 13 30
            Set Label to "End"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oDOCTOR_LAST_NAME is a dbForm
            Entry_Item DOCTOR.LAST_NAME
            Set Location to 39 11
            Set Size to 13 120
            Set Label to "Last Name"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oDOCTOR_FIRST_NAME is a dbForm
            Entry_Item DOCTOR.FIRST_NAME
            Set Location to 39 162
            Set Size to 13 119
            Set Label to "First Name"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oSearchApptsBtn is a Button
            Set Size to 14 67
            Set Location to 58 11
            Set Label to "&Search Appt Times"
            Procedure OnClick
                Date dDate
                Integer iDoc# iSelectedTime
                Boolean bAcceptedSelection
                
                Get Value of oAPPT_DATE to dDate
                Get Value of oAPPT_DOCTOR_ to iDoc#
                If ((dDate <> "") and (DoctorExistsInDb(Self, iDoc#))) Begin
                    Send SetModalProperties of oDoctorAvailabilitySL dDate iDoc#
                    Send Popup of oDoctorAvailabilitySL
                    Get DidAcceptSelection of oDoctorAvailabilitySL to bAcceptedSelection
                    If (bAcceptedSelection) Begin
                        Get AcceptedTime of oDoctorAvailabilitySL to iSelectedTime
                        Get AcceptedDate of oDoctorAvailabilitySL to dDate
                        Get AcceptedDoctor of oDoctorAvailabilitySL to iDoc#
                        Set Field_Changed_Value of oAPPT_DD Field APPT.Time to iSelectedTime
                        Set Field_Changed_Value of oAPPT_DD Field APPT.Date to dDate
                        Set Field_Current_Value of oDOCTOR_DD Field DOCTOR.DOCTOR# to iDoc#
                    End
                End
                Else Send Info_Box "Please select a doctor and a date." (psMboxCaption(Self))
            End_Procedure
        
        End_Object
    End_Object

    Object oFilterGroup is a Group
        Set Size to 39 311
        Set Location to 167 15
        Set Label to "Filter"

        Object oMorningAfternoonFilter is a RadioGroup
            Set Location to 8 10
            Set Size to 27 193
        
            Object oRadio1 is a Radio
                Set Label to "Next appt."
                Set Size to 10 61
                Set Location to 9 5
            End_Object
        
            Object oRadio2 is a Radio
                Set Label to "Next AM appt."
                Set Size to 10 61
                Set Location to 9 57
            End_Object
        
            Object oRadio3 is a Radio
                Set Label to "Next PM appt."
                Set Size to 10 61
                Set Location to 9 129
            End_Object
        
            Procedure Notify_Select_State Integer iToItem Integer iFromItem
                Forward Send Notify_Select_State iToItem iFromItem
            End_Procedure
        End_Object

        Object oSelectedDoctorChkBox is a CheckBox
            Set Size to 10 50
            Set Location to 9 226
            Set Label to "Selected Doctor"
        End_Object

        Object oNextApptBtn is a Button
            Set Size to 14 83
            Set Location to 21 217
            Set Label to "Find Next A&ppointment"
        
            Procedure OnClick
                DateTime dtQueued
                TAppointment tAppt
                Integer iTimeFilter iDoc#
                Integer[] aiFilteredTimes
                Boolean bIsFilterByDoctor

                Get QueueNextDateTime of oTimeKeeper to dtQueued
                Get Current_Radio of oMorningAfternoonFilter to iTimeFilter
                Get Checked_State of oSelectedDoctorChkBox to bIsFilterByDoctor
                If (bIsFilterByDoctor) Get Field_Current_Value of oDOCTOR_DD Field DOCTOR.DOCTOR# to iDoc#
                Else Move 0 to iDoc#
                
                If (not(bIsFilterByDoctor) or (bIsFilterByDoctor and (DoctorExistsInDb(Self, iDoc#)))) Begin
                    Get GetFilteredTimesSet iTimeFilter to aiFilteredTimes
                    Get FindNextAppointment dtQueued iDoc# aiFilteredTimes to tAppt
                    Set Field_Current_Value of oDOCTOR_DD Field DOCTOR.DOCTOR# to tAppt.iDoc#
                    Send SetDateTimeFields of oTimeKeeper tAppt.dtDateTime
                End
                Else Send Info_Box "Please select a doctor from the selection prompt." (psMboxCaption(Self))
            End_Procedure
        End_Object
    End_Object

    Object oAppointmentContainer is a dbContainer3d
        Set Size to 52 311
        Set Location to 216 15
        Set Label to "Appt"
        Set Server to oAPPT_DD

        Object oAPPT_APPT_ is a dbForm
            Entry_Item APPT.APPT#
            Set Location to 14 43
            Set Size to 13 51
            Set Label to "Appt #"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object
        Object oAPPT_DATE is a dbForm
            Entry_Item APPT.Date
            Set Location to 14 99
            Set Size to 13 60
            Set Label to "Date"
            Set Prompt_Button_Mode to PB_PromptOn
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
            
            Procedure Prompt
                Send Popup to Popup_Calendar
            End_Procedure
            
        End_Object
        Object oAPPT_TIME is a dbForm
            Entry_Item APPT.Time
            Set Location to 14 164
            Set Size to 13 51
            Set Label to "Time"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
            
            Procedure Prompt
                Integer iTime
                
                Send Popup of oOfficeTimesSL
                If (DidAcceptSelection(oOfficeTimesSL)) Begin
                    Get GetSelectedTime of oOfficeTimesSL to iTime
                    Set Field_Changed_Value of oAPPT_DD Field APPT.Time to iTime
                End
            End_Procedure
            
            Procedure Prompt_Callback Integer hPrompt
                Integer iCurrentTime iHr iMin
                Integer[] aiTimes
                Date dDate
                DateTime dtTD dtTDNext
                
                Move (CurrentDateTime()) to dtTD
                
                Get GetFilteredTimesSet CI_NEXT_APPT to aiTimes
                Get FindNextTimeSlot dtTD aiTimes to dtTDNext
                
                Set piUpdateColumn of hPrompt to 0
                Set psSeedValue of hPrompt to (DateGetMilitaryTime(dtTDNext))
            End_Procedure
        End_Object

        Object oAPPT_REASON is a dbForm
            Entry_Item APPT.REASON
            Set Location to 14 220
            Set Size to 13 51
            Set Label to "Reason"
            Set Label_Justification_Mode to JMode_Top
            Set Label_Col_Offset to 0
        End_Object

        Object oNewApptBtn is a Button
            Set Size to 14 75
            Set Location to 30 12
            Set Label to "New App&ointment"
        
            Procedure OnClick
                Integer iChoice
                Get Message_Box "Are you sure you wish to clear all fields?" (psMboxCaption(Self)) MB_YESNO MB_ICONQUESTION to iChoice
                If (iChoice = MBR_Yes) Begin
                    Send Clear of oAPPT_DD
                    Set Checked_State of oSelectedDoctorChkBox to False
                    Set Current_Radio of oMorningAfternoonFilter to 0
                    Send ResetTimeKeeper of oTimeKeeper
                End
            End_Procedure
        
        End_Object

        Object oConfirm is a Button
            Set Size to 14 64
            Set Location to 30 223
            Set Label to "Confir&m"
            Set FontWeight to 800
        
            Procedure OnClick
                Boolean bFail
                
                Set pbApptSaveSuccess to False
                Get Request_Validate of oAPPT_DD to bFail
                If (not(bFail)) Begin 
                    Send Request_Save_No_Clear of oAPPT_DD
                    If (pbApptSaveSuccess(Self)) Send Info_Box ;
                        ("Appt #" + String(APPT.APPT#) * ;
                        "has been set with Doctor" * Doctor.LAST_NAME * ;
                        "at" * (PresentTimeAsCivilian(Self, APPT.Time)) * ;
                        "on" * String(APPT.Date) + ".") (psMboxCaption(Self))
                End
            End_Procedure
        End_Object
    End_Object
    
    //manages incrementing/displaying incremented times with find next appointment functionality
    Object oTimeKeeper is a cObject 
        Property DateTime pdtPreviousHolder
        Property Boolean pbFirstLoad //on first displaying a date/time after a reset, check the initial time first before incrementing to next time
        
        Function QueueNextDateTime Returns DateTime
            Integer iTime
            DateTime dtFieldDateTime
            
            Get Field_Current_Value of oAPPT_DD Field APPT.Time to iTime
            Get Field_Current_Value of oAPPT_DD Field APPT.Date to dtFieldDateTime
            Move (DateSetMilitaryTime(dtFieldDateTime,iTime)) to dtFieldDateTime
            
            If (not(pbFirstLoad(Self))) Begin
                Move (DateGetMilitaryTime(dtFieldDateTime)) to iTime
                Increment iTime
                Move (DateSetMilitaryTime(dtFieldDateTime, iTime)) to dtFieldDateTime
            End
            If (dtFieldDateTime < (CurrentDateTime())) Move (CurrentDateTime()) to dtFieldDateTime
            Set pbFirstLoad to False
            Function_Return dtFieldDateTime
        End_Function
        
        Procedure SetDateTimeFields DateTime dtDateTime
            Integer iTime
            
            Set pdtPreviousHolder to dtDateTime
            Move (DateGetMilitaryTime(dtDateTime)) to iTime
            Set Field_Changed_Value of oAPPT_DD Field APPT.Time to iTime
            Set Field_Changed_Value of oAPPT_DD Field APPT.Date to dtDateTime
        End_Procedure
        
        Procedure ResetTimeKeeper
            DateTime dtCurrent dtNext
        	Integer iTime
        	Integer[] aiTimes
            
            Set pbFirstLoad to True
        	
        	Move (CurrentDateTime()) to dtCurrent
        	Get GetFilteredTimesSet CI_NEXT_APPT to aiTimes
        	Get FindNextTimeSlot dtCurrent aiTimes to dtNext
        	Get DateGetMilitaryTime dtNext to iTime
        	
        	Set Field_Changed_Value of oAPPT_DD Field APPT.Date to dtNext
        	Set Field_Changed_Value of oAPPT_DD Field APPT.Time to iTime
        End_Procedure
    End_Object
    
    Procedure Seed_Data_Sets
    	Send ResetTimeKeeper of oTimeKeeper
    End_Procedure
    
    On_Key Key_Alt+Key_S Send OnClick of oSearchApptsBtn
    On_Key Key_Alt+Key_P Send OnClick of oNextApptBtn
    On_Key Key_Alt+Key_O Send OnClick of oNewApptBtn
    On_Key Key_Alt+Key_M Send OnClick of oConfirm
Cd_End_Object
